package com.goktech.olala.server.dao.sys;

import com.goktech.olala.server.pojo.sys.SysRoleMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author wusq
 * 系统角色菜单 dao层
 */
public interface SysRoleMenuDao {
    /**
     * 删除
     * @param rmId
     * @return
     */
    int deleteByPrimaryKey(Long rmId);

    /**
     * 新增
     * @param record
     * @return
     */
    int insert(SysRoleMenu record);

    /**
     * 查询
     * @param rmId
     * @return
     */
    SysRoleMenu selectByPrimaryKey(Long rmId);

    /**
     * 多条件的查询
     * @param roleId
     * @param menuId
     * @return
     */
    @Select("<script>"+
            "SELECT RM.RM_ID rmId, RM.ROLE_ID roleId, RM.MENU_ID menuId FROM SYS_ROLE_MENU RM "+
            "<where>"+
            "1=1"+
                "<if test='roleId != null'>" +
                    " AND RM.ROLE_ID = #{roleId}"+
                "</if>"+
                "<if test='menuId != null'>" +
                    " AND RM.MENU_ID = #{menuId}"+
                "</if>"+
            "</where>"+
            "</script>")
    List<SysRoleMenu> selectByExample(@Param("roleId") Long roleId, @Param("menuId") Long menuId);

    /**
     * 更新
     * @param record
     * @return
     */
    int updateByPrimaryKey(SysRoleMenu record);

    /**
     * 带条件的删除
     * @param roleId
     * @param menuId
     * @return
     */
    @Delete("<script>"+
            "DELETE FROM SYS_ROLE_MENU RM "+
            "<where>"+
                "1=1"+
                "<if test='roleId != null'>" +
                    " AND RM.ROLE_ID = #{roleId}"+
                "</if>"+
                "<if test='menuId != null'>" +
                    " AND RM.MENU_ID = #{menuId}"+
                "</if>"+
            "</where>"+
            "</script>")
    int deleteByExample(@Param("roleId") Long roleId, @Param("menuId") Long menuId);
}